<template>
	<view class="">
		<u-subsection :list="list" v-model="current" @change="zjchange"></u-subsection>
		<view class="shows">
			<view class="" style="padding:0 30rpx;" v-for="(doctor,index) in doctorlist" :key="index">
				<view class="imglist" @click="setdoctor(doctor.DoctorId)">
					<view class="imgleft">
						<!-- <u--image :src="doctor.HeadImg" width="90" height="100"></u--image> -->
						<u-avatar :src="doctor.HeadImg" size='180'></u-avatar>
					</view>
					<view class="imgcount">
						<view class="name dis">{{doctor.DoctorName}}<view class="tab gray font25">&ensp;{{doctor.CompanyName}} {{doctor.WorkType}}</view></view>
						<!-- <span class="tab">{{doctor.CompanyName}} {{doctor.WorkType}}</span> -->
						<!-- <span class="describe">{{doctor.WorkDuty}}</span> -->
						<span class="describe" v-if="doctor.Describe==''">{{doctor.WorkDuty}}</span>
						<span class="describe" v-else>{{doctor.Describe}}</span>
					</view>
				</view>
				<!-- <u-divider></u-divider> -->
			</view>
			<span @click="getlist"><u-loadmore :status="status" /></span>
			<view class="botu">

			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
						name: '本院专家'
					},
					{
						name: '名院名家',
					}

				],
				zjname:'本院专家',
				current: 0,
				status: 'loadmore',
				page: 1,
				rows: 6,
				doctorlist: [],
				keyword: ''
			}
		},
		onLoad: function(onction) {
			console.log("医生", onction)
			this.getdoctor()
			return
			if (onction) {
				this.keyword = onction.keyword
				this.Search()
			} else {
				
				this.getdoctor()
			}

		},
		created() {
			
		},
		onReachBottom() {
			this.getlist()
		},
		onPullDownRefresh() {
			this.getdoctor()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 800);
				return
			if (this.keyword == '') {
				this.getdoctor()
			} else {
				this.Search()
			}
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 800);
		},
		methods: {
			zjchange(index) {
				console.log("index", index)
				this.zjname=this.list[index].name
				this.getdoctor()
			},
			Search() {
				this.doctorlist=[]
				this.$request('Doctor', 'Search', {
					page: this.page,
					rows: this.rows,
					KeyValue: this.keyword
				}).then(res => {
					// this.doctorlist=[]
					let doctor = res.data.rows
					if(res.code==1){
						if (doctor.length > 0) {
							this.doctorlist = doctor
							this.status = "loadmore"
						}
						if (doctor.length % 6 > 0) {
							this.status = "nomore"
						}
					}
					console.log(this.doctorlist)
				})
			},
			getlist() {
				this.page += 1
				this.status = "loading"
				this.getdoctor()
				return
				if (this.keyword == '') {
					this.getdoctor()
				} else {
					this.Search()
				}

			},
			setdoctor(DoctorId) {
				// let doctors = JSON.stringify(doctor)
				uni.navigateTo({
					url: `/pages/doctor/doctorlist/doctorlist?DoctorId=${DoctorId}`,
					fail(error) {
						console.log(error)
					}
				})
			},
			async getdoctor() {
				if(this.status!="nomore"){
					// this.doctorlist=[]
				}
				
				this.$request('Doctor', 'Doctor', {
					page: this.page,
					rows: this.rows,
					Companyld: '',
					Departmentld: '',
					Doctype:this.zjname
				}).then(res => {
					console.log(res)
					// this.doctorlist=[]
					
					if(res.code==1){
						let doctor = res.data.rows
						if (doctor.length > 0) {
							this.doctorlist = this.doctorlist.concat(doctor)
							this.status = "loadmore"
						}else{
							this.status = "nomore"
						}
						// if (doctor.length % 6 > 0) {
						// 	this.status = "nomore"
						// }
					}
					console.log("this.doctorlist",this.doctorlist)
				})
			}
		}

	}
</script>

<style>
	@import './doctor.css'
</style>


<style lang="scss" scoped>
	.wrap {
		padding: 24rpx;
	}

	.item {
		padding: 24rpx 0;
		color: $u-content-color;
		font-size: 28rpx;
	}
</style>